_Pragma("once")

#include <netinet/in.h>

#include "ICommunicator.h"
#include "StringUtility.h"
#include "IpAddressInfo.h"


class INetwork;

class UdpCommunicator : public ICommunicator {
public:
    static constexpr uint32_t SPEED = 1 * 1000* 1000;
    static constexpr size_t DEBUG_OUTPUT_SIZE = 100;

    /** Default constructor */
    UdpCommunicator() {

    }
    /** Default destructor */
    ~UdpCommunicator();


    bool allocHandle(void) noexcept;

    int bindToInterface(INetwork& pnetwork);

    bool setTimeout(INetwork& pnetwork) noexcept;

    bool setTimeout(const timeval& timeout) noexcept;


    bool connect(const IpAddressInfo& ipAddressInfo) noexcept;

    bool close(void) noexcept override;

    virtual ssize_t sendRaw(const void* data, size_t length) noexcept;

    virtual ssize_t recvRaw(void* buffer, size_t length) noexcept;


    int msocket{0};

    sockaddr_in mtargetIpAddress;
    sockaddr_in msourceIpAddress[2];
};
